package com.iflysse.controller;

import com.iflysse.common.ResultEnum;
import com.iflysse.pojo.bo.CommonBoResp;
import com.iflysse.pojo.bo.req.*;
import com.iflysse.pojo.bo.resp.CourseStateBoResp;
import com.iflysse.pojo.bo.resp.TeacherAllClassBoResp;
import com.iflysse.pojo.bo.resp.TeacherClassBoResp;
import com.iflysse.pojo.bo.resp.TeacherClassUpdateBoResp;
import com.iflysse.pojo.vo.common.CommonVoResp;
import com.iflysse.pojo.vo.req.*;
import com.iflysse.pojo.vo.resp.*;
import com.iflysse.services.TeacherClassService;
import com.iflysse.util.CommonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/teacherClass")
@Api(value = "教师端班级接口")
@Log4j
public class TeacherClassController {


    @Autowired
    private TeacherClassService teacherClassService;


    /**
     * 教师端查询我的教学班级列表接口
     * @param teacherClassVoReq
     * @return
     */
    @PostMapping("/queryAllClass")
    @ApiOperation(value = "查询班级列表")
    public TeacherAllClassVoResp queryAllClass(TeacherClassVoReq teacherClassVoReq){

        TeacherAllClassVoResp teacherAllClassVoResp=new TeacherAllClassVoResp();
        try{

            log.info("查询教师端班级列表接口参数："+teacherClassVoReq);
            TeacherClassBoReq teacherClassBoReq=CommonUtil.objToObj(teacherClassVoReq,TeacherClassBoReq.class);
            teacherClassBoReq.setAccountId(teacherClassVoReq.getUserId());
            TeacherAllClassBoResp teacherAllClassBoResp= teacherClassService.queryAllClassByUserId(teacherClassBoReq);
            log.info("查询教师端班级列表接口业务层响应bean："+teacherAllClassBoResp);

            teacherAllClassVoResp.setMsg(ResultEnum.SUCCESS.getMsg());
            teacherAllClassVoResp.setCode(ResultEnum.SUCCESS.getCode());
            teacherAllClassVoResp.setResult(teacherAllClassBoResp.getResult());
            log.info("教师端查询班级列表响应bean信息："+teacherAllClassVoResp);
            return teacherAllClassVoResp;

        }catch (Exception e){
            log.error("教师端查询班级列表出现异常，信息为："+e);
            CommonUtil.printError(teacherAllClassVoResp);
            log.info("教师端查询班级列表响应bean信息："+teacherAllClassVoResp);
            return teacherAllClassVoResp;
        }
    }


    /**
     * 创建教学班级接口
     * @param addTeacherClassVoReq
     * @return
     */
    @PostMapping("/addTeacherClass")
    @ApiOperation(value = "创建教学班级接口")
    public CommonVoResp addTeacherClass(AddTeacherClassVoReq addTeacherClassVoReq){
        CommonVoResp commonVoResp=new CommonVoResp();

        try{
            log.info("教师端创建班级参数为："+addTeacherClassVoReq);
            AddTeacherClassBoReq addTeacherClassBoReq=  CommonUtil.objToObj(addTeacherClassVoReq, AddTeacherClassBoReq.class);
            log.info("教师端创建班级业务员接口参数为："+addTeacherClassBoReq);
            CommonBoResp commonBoResp= teacherClassService.addTeacherClass(addTeacherClassBoReq);

            CommonUtil.printBoResultToVoResult(commonBoResp,commonVoResp);
            log.info("教师端创建班级响应bean信息："+commonVoResp);
            return commonVoResp;
        }catch (Exception e){
            log.error("教师端创建班级出现异常，信息为："+e);
            CommonUtil.printError(commonVoResp);
            log.info("教师端创建班级响应bean信息："+commonVoResp);
            return commonVoResp;
        }
    }

    /**
     * 删除教学班级接口
     * @param deleteTeacherClassVoReq
     * @return
     */
    @PostMapping("/deleteTeacherClass")
    @ApiOperation(value = "删除教学班级接口")
    public CommonVoResp deleteTeacherClass(DeleteTeacherClassVoReq deleteTeacherClassVoReq){
        CommonVoResp commonVoResp=new CommonVoResp();

        try{
            log.info("教师端删除班级请求参数："+deleteTeacherClassVoReq);

            DeleteTeacherClassBoReq deleteTeacherClassBoReq= CommonUtil.objToObj(deleteTeacherClassVoReq, DeleteTeacherClassBoReq.class);
            log.info("教师端删除班级请求业务接口参数："+deleteTeacherClassBoReq);
            CommonBoResp commonBoResp= teacherClassService.deleteTeacherClass(deleteTeacherClassBoReq);
            CommonUtil.printBoResultToVoResult(commonBoResp,commonVoResp);
            log.info("教师端删除班级响应bean信息："+commonVoResp);
            return commonVoResp;

        }catch (Exception e){
            log.error("教师端删除班级出现异常，信息为："+e);
            CommonUtil.printError(commonVoResp);
            log.info("教师端删除班级响应bean信息："+commonVoResp);
            return commonVoResp;
        }
    }



    /**
     * 教师端教学班级的详情信息查询接口（教学活动和班级学生上方信息接口）
     * @param teachingClassIdVoReq
     * @return
     */
    @PostMapping("/queryClassInfo")
    @ApiOperation(value = "教师端教学班级的详情信息查询接口（包含教学活动和班级学生上方信息接口）")
    public TeacherClassVoResp queryClassInfo(TeachingClassIdVoReq teachingClassIdVoReq){
        TeacherClassVoResp teacherClassVoResp=new TeacherClassVoResp();

        try {

            log.info("教师端教学班级的详情信息查询接口（包含教学活动和班级学生上方信息接口）参数bean:"+teachingClassIdVoReq);
            TeachingClassIdBoReq teachingClassIdBoReq= CommonUtil.objToObj(teachingClassIdVoReq, TeachingClassIdBoReq.class);
            log.info("教师端教学班级的详情信息查询接口参数："+teachingClassIdBoReq);
            TeacherClassBoResp teacherClassBoResp= teacherClassService.getTeacherClassByClassId(teachingClassIdBoReq);
            TeacherClassResp result=  CommonUtil.objToObj(teacherClassBoResp, TeacherClassResp.class);
            TeacherClassUpdateBoResp teacherClassUpdateBoResp= teacherClassService.getUpdateTeacherClassByClassId(teachingClassIdBoReq);
            CourseStateBoResp courseStateBoResp=teacherClassUpdateBoResp.getCourseStateBoResp();

            result.setCourseName(courseStateBoResp.getCourseName());//课程名字
            result.setCouldByChange(courseStateBoResp.getCouldByChange());//是否可被更改
            teacherClassVoResp.setResult(result);
            teacherClassVoResp.setCode(ResultEnum.SUCCESS.getCode());
            teacherClassVoResp.setMsg(ResultEnum.SUCCESS.getMsg());
            log.info("教师端教学班级的详情信息查询响应bean:"+teacherClassVoResp);
            return teacherClassVoResp;
        }catch (Exception e){
            log.error("教师端教学班级的详情信息查询接口出现异常："+e);
            CommonUtil.printError(teacherClassVoResp);
            return teacherClassVoResp;
        }
    }

    /**
     * 老师端修改班级信息
     */
    @PostMapping("/updateClassInfo")
    @ApiOperation(value = "老师端修改班级信息")
    public CommonVoResp updateClassInfo(UpdateTeacherClassVoReq updateTeacherClassVoReq){

        CommonVoResp commonVoResp=new CommonVoResp();
        try {
            log.info("老师端修改班级信息参数："+updateTeacherClassVoReq);
            UpdateTeacherClassBoReq updateTeacherClassBoReq= CommonUtil.objToObj(updateTeacherClassVoReq,UpdateTeacherClassBoReq.class);
            updateTeacherClassBoReq.setTeachingClassName(updateTeacherClassVoReq.getClassName());
            log.info("老师端修改班级信息调用业务接口参数："+updateTeacherClassBoReq);
            CommonBoResp commonBoResp= teacherClassService.updateTeacherClass(updateTeacherClassBoReq);
            CommonUtil.printBoResultToVoResult(commonBoResp,commonVoResp);
            log.info("老师端修改班级信息响应bean："+commonVoResp);
            return commonVoResp;
        }catch (Exception e){
            log.error("老师端修改班级信息出现异常："+e);
            CommonUtil.printError(commonVoResp);
            return commonVoResp;
        }
    }



}
